using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.DirectoryServices;
using Suucha.Adsi;
using Suucha.Adsi.Configuration;

namespace Suucha.AdHelper
{
    public sealed class Common
    {
        private static AdsiSettings adsiSettings = Adsi.Config.GetLdapSettings();
        internal static string ADPath = adsiSettings.Path; 
        internal static string UserName = adsiSettings.UserName;
        internal static string Password = adsiSettings.Password;
        /*
        internal static Guid CovertNativeGuid(byte[] nativeGuid)
        {
            return new Guid(nativeGuid);
        }

        internal static Guid CovertNativeGuid(ResultPropertyValueCollection nativeGuid)
        {
            byte[] b = (byte[])nativeGuid[0];
            return new Guid(b);
        }

        internal static Guid CovertNativeGuid(ResultPropertyCollection result)
        {
            byte[] b = (byte[])result["objectGUID"][0];
            return new Guid(b);
        }
         * */

        internal static Guid GetGuid(SearchResult result)
        {
            byte[] b = (byte[])result.Properties["objectGUID"][0];
            return new Guid(b);
        }

        internal static string Guid2OctetString(Guid id)
        {
            byte[] b = id.ToByteArray();
            string octel = "";
            for (int i = 0; i < b.GetLength(0); i++)
            {
                octel += "\\" + b[i].ToString("X2");
            }
            return octel;
        }

    }
}
